/**
 * 根据评定标度获取扣分值
 * @param deductionScale  评定标度
 * @param maxScale        最大标度
 * @return {number}       扣分值
 */
export const getDeductionPoint = (deductionScale, maxScale) => {
  let threeScale = [0, 20, 35];
  let fourScale = [0, 25, 40, 50];
  let fiveScale = [0, 35, 45, 60, 100];
  switch(maxScale) {
    case 3:
      return threeScale[deductionScale-1];
    case 4:
      return fourScale[deductionScale-1];
    case 5:
      return fiveScale[deductionScale-1];
    default:
      return 0;
  }
};

/**
 * 将桥梁评分转为等级
 * @param point  评分
 */
export const pointToLevel = (point)=>{
  if(point === null || point === undefined || isNaN(point)) return "尚未评定";
  if(point <40) return "5类";
  else if(point < 60) return "4类";
  else if(point < 80) return "3类";
  else if(point < 95) return "2类";
  else return "1类";
};

/**
 * 获取不同桥梁等级对应的颜色
 * @param level  桥梁等级，1类、2类...5类
 */
export const getBridgeEvaluationColor = (level)=>{
  switch (level) {
    case "1类":
      return "success";
    case "2类":
      return "success";
    case "3类":
      return "primary";
    case "4类":
      return "warning";
    case "5类":
      return "danger";
    default:
      return "success";
  }
};

/**
 * 导出评定详表对象
 * @param positionEvaluationList
 * @return {Array}
 */
export const mixEvaluationDto = (positionEvaluationList)=>{
  let mixArray = [];
  positionEvaluationList.forEach((position, positionIndex, positionList)=>{
    let positionChange = true;
    position.partsEvaluationList.forEach((parts, partsIndex, partsList)=>{
      let partsChange = true;
      //没有添加过该部件的情况
      if(Array.isArray(parts.memberTypeEvaluationList) && parts.memberTypeEvaluationList.length > 0) {
        parts.memberTypeEvaluationList.forEach((memberType, memberTypeIndex, memberTypeList)=>{
          let memberTypeChange = true;
          //只有构件类型，但是没有病害
          if(Array.isArray(memberType.siteEvaluationList) && memberType.siteEvaluationList.length > 0) {
            memberType.siteEvaluationList.forEach((site, siteIndex, siteList)=>{
              let siteChange = true;
              site.memberEvaluationList.forEach((member, memberIndex, memebrList)=>{
                let memberChange = true;
                member.deductionList.forEach((deduction, deductionIndex, deductionList)=>{
                  let mixObj = {};
                  if(positionChange) {
                    mixObj.positionTypeName = position.positionTypeName;
                    mixObj.positionWeight = position.weight;
                    mixObj.positionPoint = position.point;
                    mixObj.positionRowSpan = position.rowSpan;
                    positionChange = false;
                  }
                  if(partsChange) {
                    mixObj.partsTypeName = parts.partsTypeName;
                    mixObj.originalWeight = parts.originalWeight;
                    mixObj.resizeWeight = parts.resizeWeight;
                    mixObj.partsPoint = parts.point;
                    mixObj.partsRowSpan = parts.rowSpan;
                    partsChange = false;
                  }
                  if(memberTypeChange) {
                    mixObj.memberTypeName = memberType.memberTypeName;
                    mixObj.memberCount = memberType.memberCount;
                    mixObj.memberTypeRowSpan = memberType.rowSpan;
                    memberTypeChange = false;
                  }
                  if(siteChange) {
                    mixObj.siteNo = "第"+site.siteNo+"孔";
                    mixObj.siteRowSpan = site.rowSpan;
                    siteChange = false;
                  }
                  if(memberChange) {
                    mixObj.bridgeMemberName = member.bridgeMemberName;
                    mixObj.bridgeMemberPoint = member.point;
                    mixObj.bridgeMemberRowSpan = member.rowSpan;
                    memberChange = false;
                  }
                  mixObj.evaluationIndexName = deduction.evaluationIndexName;
                  mixObj.deductionScale = deduction.deductionScale;
                  mixObj.deductionPoint = deduction.deductionPoint;

                  //存入数组
                  mixArray.push(mixObj);
                })
              })
            })
          } else {
            let mixObj = {};
            if(positionChange) {
              mixObj.positionTypeName = position.positionTypeName;
              mixObj.positionWeight = position.weight;
              mixObj.positionPoint = position.point;
              mixObj.positionRowSpan = position.rowSpan;
              positionChange = false;
            }
            if(partsChange) {
              mixObj.partsTypeName = parts.partsTypeName;
              mixObj.originalWeight = parts.originalWeight;
              mixObj.resizeWeight = parts.resizeWeight;
              mixObj.partsPoint = parts.point;
              mixObj.partsRowSpan = parts.rowSpan;
              partsChange = false;
            }
            if(memberTypeChange) {
              mixObj.memberTypeName = memberType.memberTypeName;
              mixObj.memberCount = memberType.memberCount;
              mixObj.memberTypeRowSpan = memberType.rowSpan;
              memberTypeChange = false;
            }
            mixObj.siteNo = "/";
            mixObj.bridgeMemberName = "/";
            mixObj.bridgeMemberPoint = "/";
            mixObj.evaluationIndexName = "/";
            mixObj.deductionScale = "/";
            mixObj.deductionPoint = "/";
            //存入数组
            mixArray.push(mixObj);
          }
        })
      }else{
        let mixObj = {};
        if(positionChange) {
          mixObj.positionTypeName = position.positionTypeName;
          mixObj.positionWeight = position.weight;
          mixObj.positionPoint = position.point;
          mixObj.positionRowSpan = position.rowSpan;
          positionChange = false;
        }
        if(partsChange) {
          mixObj.partsTypeName = parts.partsTypeName;
          mixObj.originalWeight = parts.originalWeight;
          mixObj.resizeWeight = !!parts.resizeWeight?parts.resizeWeight:"/";
          mixObj.partsPoint = !!parts.point?parts.point:"/";
          mixObj.partsRowSpan = parts.rowSpan;
          partsChange = false;
        }
        mixObj.memberTypeName = "/";
        mixObj.memberCount = "/";
        mixObj.siteNo = "/";
        mixObj.bridgeMemberName = "/";
        mixObj.bridgeMemberPoint = "/";
        mixObj.evaluationIndexName = "/";
        mixObj.deductionScale = "/";
        mixObj.deductionPoint = "/";
        //存入数组
        mixArray.push(mixObj);
      }
    })
  });
  return mixArray;
};



// WEBPACK FOOTER //
// ./src/assets/js/utils/EvaluationUtils.js